/**
 * Created by bgy on 2016/12/1.
 */
import React from 'react';
import {Link} from 'react-router';
import $ from '../../sources/jquery-2.2.4';

document.onclick = function (e) {
  if (e.target.tagName == 'BODY') {
    $('.pCenter').addClass('hidden');
  }
}
var User = React.createClass({
  showPCenter(){
    const pCenter = this.refs.pCenter;
    pCenter.classList.remove('hidden');
  },
  hidePCenter(){
    const pCenter = this.refs.pCenter;
    pCenter.classList.add('hidden');
  },
  render() {
    var vendorInfo = this.props.vendorInfo;
    var isLogin = this.props.isLogin;
    var user = this.props.user;
    if (isLogin) {
      if (vendorInfo.verifyStatus == 'C') {//已通过审核，登录成功。
        return (
          <div className="user isLogin">
            <div><img src="images/main/head_sculpture_gray@2x.png" alt=""/>
              <span onClick={this.showPCenter} className="pCenterBtn">...</span>
              <div ref="pCenter" onBlur={this.hidePCenter} className="pCenter hidden">
                <div style={{padding:'10px'}}>
                  <Link to="messageCenter">我的消息</Link>
                </div>
                <hr/>
                <Link style={{padding:'10px'}} to="systemSet">系统设置</Link>
              </div>
            </div>
            <span>{user.account}</span>
            <span>{vendorInfo.vendorName}</span>
          </div>
        );
      } else {
        return (
          <div className="user isLogin">
            <div><img src="images/main/head_sculpture_gray@2x.png" alt=""/>
              <span onClick={this.showPCenter} className="pCenterBtn">...</span>
              <div ref="pCenter" onBlur={this.hidePCenter} className="pCenter hidden">
                <div style={{padding:'10px'}}>
                  <Link to="messageCenter">我的消息</Link>
                </div>
                <hr/>
                <div style={{padding:'10px'}}>系统设置</div>
              </div>
            </div>
            <span>{user.account}</span>
            <span>您的审核资料已经提交，请耐心等待审核结果~</span>
            <div><span>进行水果质检可以提高审核通过率</span>&nbsp;<Link to="appFQI"><span style={{marginLeft:'0.6rem',marginRight:'0.4rem',color:'#fbe924'}}>申请质检</span>></Link></div>
          </div>
        );
      }
    } else {
      return (
        <div className="user">
          <img src="images/main/head_sculpture_gray@2x.png" alt=""/>
          <div className="toLogin">
            <Link to="login">登录</Link><span style={{marginLeft:'1.45rem',marginRight:'1.45rem',color:'#fff',textAlign:'center'}}>|</span><Link to="register">注册</Link>
          </div>
        </div>
      );
    }
  }
})
export default User;
